//
// Created by 吴喆 on 2020/3/6.
//

#ifndef SUMMER_ANIMATION_H
#define SUMMER_ANIMATION_H

#include <vector>
#include "Time.h"

class Texture2D;

class Animation {
public:
    explicit Animation(int interval, bool isLoop = true);

    void update();
    Texture2D *updateAndGetCurrentFrame();

    Texture2D *getCurrentFrame();

    /**
     * 是否完成放映
     */
    bool isOver = false;

    /**
     * 是否循环
     */
    bool isLoop = true;


    /**
     * 添加帧
     * @param frameNo 第几帧
     * @param texture
     */
    void addFrame(Texture2D *texture);

    void setInterval(int interval);

    void refresh();

protected:

    /**
     * 存放帧
     */
    std::vector<Texture2D *> textures;

    /**
     * current texture
     */
    Texture2D *currentTexture;

private:
    /**
     * 时间间隔
     */
    int interval = 1000;
    CTime *time;

    // 播放帧的数量
    int count = 0;

    bool flag = false;

    unsigned int lastFrameNo;

    float lastTime = 0;
};


#endif //SUMMER_ANIMATION_H
